package org.geektimes.projects.user.exception;

import org.geektimes.projects.user.domain.User;

import javax.validation.ConstraintViolation;
import java.util.HashSet;
import java.util.Set;

/**
 * 参数不合法
 * @author Sanhong
 */
public class InvalidParamException extends IllegalStateException {
    private final Set<ConstraintViolation<Object>> constraintViolations;

    public <T> InvalidParamException(Set<ConstraintViolation<Object>> constraintViolations) {
        this.constraintViolations = constraintViolations;
    }

    /**
     * 获取异常原因
     * @return
     */
    @Override
    public String getMessage() {
        // 这里只取第一个
        ConstraintViolation constraintViolation = constraintViolations.toArray(new ConstraintViolation[1])[0];
        return constraintViolation.getMessage();
    }
}
